<?php
/*
 * 因为帝国没有用户自定义扩展函数包，所以Music模块所用到的函数全写在下面了
 * 下面是解析各个网站的函数与方法 谨慎修改
 * 代码编写：Neuropathy Mossn枫
 * 联系QQ：504590446
 * 解析出各DJ网站的试听地址 $id=对方内容ID $www=目标网站id
*/

//----------------------------根据ID解析出试听地址 可参照已有规则进行扩展
function get_dj($id,$www){
    $ch = curl_init();
	switch ($www){ //---------根据目标网站ID输出不同的方法
	  case 1: //DJYE.COM
		curl_setopt($ch, CURLOPT_URL, "http://www.djye.com/Player/".$id.".htm");
		break;
	  case 2: //36DJ.COM
		curl_setopt($ch, CURLOPT_URL, "http://www.36dj.com/play/".$id."/");
		break;
	  case 3: //72DJ.COM
		curl_setopt($ch, CURLOPT_URL, "http://www.72dj.com/play/".$id.".htm");
		break;
	  case 4: //DJ97.COM
		curl_setopt($ch, CURLOPT_URL, "http://mobi.dj97.com/m/".$id."/");
		break;
	  default:
		return "No number";
	}
	
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	$html = curl_exec($ch);//执行并获取HTML内容
	curl_close($ch);//释放curl句柄
	
	switch ($www){ //---------根据目标网站ID输出不同的方法
	  case 1: //DJYE.COM
	  	$djye_url = get_Substr($html,'| | |','|0||');//取出加密过的地址
		$cd_url = explode(",", $djye_url); //----将加密过的地址转换为数组
		//进行解码
		for($i = 0; $i < count($cd_url); $i++) {
			$u_url.=chr($cd_url[$i]);
		}
		return 'http://zj.djye.com/'.str_replace('.wma','.m4a',$u_url);
		break;

	  case 2: //36DJ.COM
		$djye_url = iconv('GB2312', 'UTF-8', get_Substr($html,'var surl="','";</script>'));//将GBK编码转换为UTF-8编码 否则中文乱码
		return 'http://dj.36dj.com:83/'.$djye_url;
		break;

	  case 3: //72DJ.COM
		$djye_url = iconv('GB2312', 'UTF-8', get_Substr($html,'var danceFilePath="','";'));//将GBK编码转换为UTF-8编码 否则中文乱码
		return 'http://dj.72dj.com:83/m4adj/'.$djye_url.'.m4a';
		break;

	  case 4: //DJ97.COM
		$djye_url = get_Substr($html,'<audio id="J_MPlayer" src="','" controls="controls"');//取出地址
		return $djye_url;
		break;

	  default:
		return "No number";
	}
}

/*取中间文本函数*/
function get_Substr($str, $leftStr, $rightStr){
    $left = strpos($str, $leftStr);
    $right = strpos($str, $rightStr,$left);
    if($left < 0 or $right < $left) return '';
    return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr));
}
?>